﻿using DataBaseConnect.App.MenuApp;
using Microsoft.AspNetCore.Mvc;
using DataBaseConnect;
using System.Security.Claims;
using System;


// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace CoreMVC.Jurisdiction.Manage.Controllers
{

    public class HomeController : BaseController
    {
        #region  构造实例化

        public IMenuAppService _menuAppService;
        public IMenuRepository _menuRepository;
        public HomeController(IMenuAppService menuAppService, IMenuRepository menuRepository)
        {
            _menuAppService = menuAppService;
            _menuRepository = menuRepository;
        }

        #endregion

        #region  视图区

        /// <summary>
        /// 系统主页
        /// </summary>
        /// <returns></returns>
        // GET: /<controller>/
        public IActionResult Main()
        {
            return View();
        }

        /// <summary>
        /// 系统顶部页
        /// </summary>
        /// <returns></returns>
        public IActionResult Top()
        {
            ViewData["RoleUserId"] = Convert.ToInt32(User.FindFirst("RoleUserId").Value);  //得到登录用户角色id
            return View();
        }

        /// <summary>
        /// 系统左边菜单列表页
        /// </summary>
        /// <returns></returns>
        public IActionResult Left()
        {
            ViewData["RoleUserId"] = Convert.ToInt32(User.FindFirst("RoleUserId").Value);  //得到登录用户角色id
            return View();
        }

        /// <summary>
        /// 系统首页
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 系统底部导航页
        /// </summary>
        /// <returns></returns>
        public IActionResult Footer()
        {
            return View();
        }

        /// <summary>
        /// 欢迎界面
        /// </summary>
        /// <returns></returns>
        public IActionResult Welcome()
        {
            return View();
        }

        #endregion

        #region 功能实现区

        /// <summary>
        /// 根据角色权限获取菜单信息
        /// </summary>
        /// <returns></returns>
        public JsonResult GetMenuList()
        {
            //获取cookie里的userid
            string userId = User.FindFirst(ClaimTypes.Sid).Value;
            int id = int.Parse(userId);
            var list = _menuRepository.GetMenuList(id);
            return Json(list);
        }

        #endregion
    }
}
